package com.cacshanghai.cac_oa_client.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.cacshanghai.cac_oa_client.R;

/**
 * Created by geyh on 2016/5/30.
 */
public class ApprovalActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    private ListView lv_approval;
    private ApprovalAdapter approvalAdapter;

    private String[] approvals = {"日报审批", "请假审批"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_approval);
        setTitle(getString(R.string.approval_manager));
        setBack();

        lv_approval = (ListView) findViewById(R.id.lv_approval);
        approvalAdapter = new ApprovalAdapter();
        lv_approval.setAdapter(approvalAdapter);
        lv_approval.setOnItemClickListener(this);

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0://日报审批
                startActivity(new Intent(ApprovalActivity.this, DailyApprovalActivity.class));
                break;
            case 1://请假审批
                startActivity(new Intent(ApprovalActivity.this, LeaveApprovalActivity.class));
                break;
            default:
                break;
        }
    }

    class ApprovalAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return approvals.length;
        }

        @Override
        public String getItem(int position) {
            return approvals[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(ApprovalActivity.this).inflate(R.layout.item_approval, null);
            }

            TextView tv_approval_name = (TextView) convertView.findViewById(R.id.tv_approval_name);
            tv_approval_name.setText(approvals[position]);

            return convertView;
        }
    }
}
